﻿using HQHS.Library.Common.Caching;
using HQHS.Library.Common.Colloection;
using HQHS.Library.Common.Factory;
using HQHS.Library.Common.Threading;
using HQHS.Library.DAO.Menu;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HQHS.Library.BLL.GOTCaching
{
    public class GOTCaching<Tkey> : CacheBase<string, IList<Tkey>>, ISingleton
    {
        public static readonly GOTCaching<Tkey> Instance = Factory<GOTCaching<Tkey>>.Create();

        #region Constructors

        private GOTCaching(string cacheKey)
            : base(cacheKey)
        {
        }

        #endregion

        #region Non-Public Methods
        protected override ICacheManager<string, List<Tkey>> GetCustomCacheManager(
            SynchronizedDictionary<string, CachedItemInfo<string, IList<Tkey>>> elementCache,
            KeyedReaderWriterLockSlim<string> contentLoadLock)
        {
            var cacheMgr = new TimestampCacheManagerAsync<string, IList<Tkey>>(
                elementCache
                , contentLoadLock
                , LoadItem
                , TimeSpan.FromMinutes(60 * 24 * 7)
                );

            return cacheMgr;
        }

        protected override object LoadItem(object key)
        {
            throw new NotImplementedException();
        }
        #endregion
    }
}
